package difangame.collision;

import difangame.Constants;
import difangame.sprite.Bug;
import framework.Collision;
import framework.Sprite;


/**
 * This class is used by the BugStar and BugStone collision classes.
 * 
 */
public abstract class BugCollision extends Collision {

    @Override
    public void update () {
        super.findAndHandleCollisions(Constants.bug, getMyNonBugSprite());
    }

    @Override
    protected void action (Sprite a, Sprite b) {
        if (a == getBug(a, b)) {
            setCarrier(a, b);
        }
        else {
            setCarrier(b, a);
        }
    }

    private Bug getBug (Sprite a, Sprite b) {
        if (Constants.bug.equals(a.getMyName())) {
            return (Bug) a;
        }
        else if (Constants.bug.equals(b.getMyName())) {
            return (Bug) b;
        }
        return null;
    }

    protected void setCarrier (Sprite a, Sprite b) {
        Bug aBug = (Bug) a;
        aBug.setMyCarrier(b);
    }

    protected abstract String getMyNonBugSprite ();
}
